package org.hank.demoproject.coil

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import androidx.databinding.DataBindingUtil.setContentView
import coil.load
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import kotlinx.coroutines.*
import org.hank.demoproject.BaseViewBindingActivity
import org.hank.demoproject.R
import org.hank.demoproject.databinding.ActivityCoilBinding

class CoilActivity : BaseViewBindingActivity<ActivityCoilBinding>() {

    val imgUrl1 = "https://gitee.com/gautohank/hank-pic-lib/raw/master/2052107.jpg"
    val imgUrl2 = "https://gitee.com/gautohank/hank-pic-lib/raw/master/2052108.jpg"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_coil)
        viewBinding.imgCoilTest.load(imgUrl1)
        viewBinding.imgCoilTest.setOnClickListener {
            when (it.tag) {
                "0" -> {
                    viewBinding.imgCoilTest.tag = "1"
                    viewBinding.imgCoilTest.load(imgUrl2)
                }
                "1" -> {
                    viewBinding.imgCoilTest.tag = "0"
                    viewBinding.imgCoilTest.load(imgUrl1)
                }
            }
        }
    }

    override fun inflateLayout(layoutInflater: LayoutInflater): ActivityCoilBinding {
        return ActivityCoilBinding.inflate(layoutInflater)
    }
}

